home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Scripts / Clean Up Finder Windows ƒ / Clean Up Finder Windows source < prev    next >
Encoding:
Text File  |  1994-12-23  |  3.1 KB  |  124 lines  |  [TEXT/ToyS]

  1. --
  2. -- release history:
  3. -- 1.0 (941223) original release
  4. --
  5. -- Known bugs and limitations:
  6. -- • Windows may end up (partly) outside the screen limits
  7. -- • Error detection and handling is poor
  8. --
  9. property topFolderXPosition : 0
  10. property topFolderYPosition : 0
  11.  
  12. on processTopFolder(theFolder)
  13.     tell application "Finder"
  14.         activate
  15.         open theFolder
  16.         set thePosition to position of window of theFolder
  17.     end tell
  18.     set topFolderXPosition to item 1 of thePosition
  19.     set topFolderYPosition to item 2 of thePosition
  20.     processFolder(theFolder, 0)
  21. end processTopFolder
  22.  
  23. on processFolder(theFolder, depth)
  24.     tell application "Finder"
  25.         activate
  26.         open theFolder
  27.         try
  28.             my moveFolder(theFolder, depth)
  29.             my sizeFolder(theFolder, depth)
  30.         on error m
  31.             -- just ignore errors. Thus, one can drop a disk which contains some folders to
  32.             -- which one does not have access
  33.         end try
  34.         set theSubFolders to (folders in theFolder)
  35.         repeat with subFolder in theSubFolders
  36.             my processFolder(subFolder, depth + 1)
  37.         end repeat
  38.         close theFolder
  39.     end tell
  40. end processFolder
  41.  
  42. on moveFolder(theFolder, depth)
  43.     -- Configure here for your preferences (and screen size)
  44.     set xpos to 18 * depth + topFolderXPosition
  45.     set ypos to 18 * depth + topFolderYPosition
  46.     if xpos > 400 then set xpos to 400
  47.     if ypos > 300 then set ypos to 300
  48.     tell application "Finder"
  49.         set position of window of theFolder to {xpos, ypos}
  50.     end tell
  51. end moveFolder
  52.  
  53. on sizeFolder(theFolder, depth)
  54.     tell application "Finder"
  55.         set numItems to count items of theFolder
  56.         -- configure here
  57.         if numItems < 9 then
  58.             tell window of theFolder
  59.                 set view to icon
  60.                 if numItems < 5 then
  61.                     set size to {400, 100} -- one row
  62.                 else
  63.                     set size to {400, 200} -- two rows
  64.                 end if
  65.                 clean up by name
  66.                 set zoomed to true
  67.             end tell
  68.         else if numItems < 25 then
  69.             tell window of theFolder
  70.                 set view to small icon
  71.                 set size to {250, 275}
  72.                 clean up by name
  73.                 set zoomed to true
  74.             end tell
  75.         else
  76.             tell window of theFolder
  77.                 set size to {450, 250} -- wide to make date readable
  78.                 --
  79.                 -- Clean up icons in case we switch back later. Don't do icon view. That
  80.                 -- would slow down an already slow program and with this many items
  81.                 -- chances are 'by Icon' will never be selected.
  82.                 --
  83.                 set view to small icon
  84.                 clean up by name
  85.                 set view to name
  86.                 reveal first item -- to scroll back to {0,0}
  87.             end tell
  88.         end if
  89.     end tell
  90. end sizeFolder
  91.  
  92. on run
  93.     set theFolder to choose folder with prompt "Select folder to clean up:"
  94.     if theFolder ≠ "" then
  95.         tell application "Finder"
  96.             my processTopFolder(folder theFolder)
  97.         end tell
  98.     end if
  99. end run
  100.  
  101. on open theFiles
  102.     set allAreFolders to true
  103.     repeat with theFile in theFiles
  104.         if last character of (theFile as string) is not ":" then
  105.             set allAreFolders to false
  106.             exit repeat
  107.         end if
  108.     end repeat
  109.     if allAreFolders then
  110.         tell application "Finder"
  111.             repeat with theFile in theFiles
  112.                 set theFolder to folder theFile
  113.                 try
  114.                     my processTopFolder(theFolder)
  115.                 on error message
  116.                     display dialog message buttons "Ok"
  117.                 end try
  118.             end repeat
  119.         end tell
  120.     else
  121.         display dialog "Drop only folders on this droplet, please!" buttons "Ok"
  122.     end if
  123. end open
  124.